home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch11 / Circle2.frm (.txt) < prev    next >
Visual Basic Form  |  1999-06-12  |  5KB  |  174 lines

  1. VERSION 5.00
  2. Begin VB.Form frmCircle2 
  3.    Caption         =   "Circle2"
  4.    ClientHeight    =   5310
  5.    ClientLeft      =   2175
  6.    ClientTop       =   645
  7.    ClientWidth     =   4830
  8.    LinkTopic       =   "Form1"
  9.    PaletteMode     =   1  'UseZOrder
  10.    ScaleHeight     =   5310
  11.    ScaleWidth      =   4830
  12.    Begin VB.TextBox txtYScale 
  13.       Height          =   285
  14.       Left            =   2160
  15.       TabIndex        =   9
  16.       Text            =   "1.0"
  17.       Top             =   480
  18.       Width           =   615
  19.    End
  20.    Begin VB.TextBox txtXScale 
  21.       Height          =   285
  22.       Left            =   600
  23.       TabIndex        =   7
  24.       Text            =   "2.0"
  25.       Top             =   480
  26.       Width           =   615
  27.    End
  28.    Begin VB.TextBox txtDt 
  29.       Height          =   285
  30.       Left            =   2160
  31.       TabIndex        =   6
  32.       Text            =   "0.1"
  33.       Top             =   45
  34.       Width           =   615
  35.    End
  36.    Begin VB.TextBox txtTmin 
  37.       Height          =   285
  38.       Left            =   0
  39.       TabIndex        =   4
  40.       Text            =   "0"
  41.       Top             =   45
  42.       Width           =   615
  43.    End
  44.    Begin VB.CommandButton cmdGo 
  45.       Caption         =   "Go"
  46.       Default         =   -1  'True
  47.       Height          =   375
  48.       Left            =   4200
  49.       TabIndex        =   3
  50.       Top             =   0
  51.       Width           =   615
  52.    End
  53.    Begin VB.TextBox txtTmax 
  54.       Height          =   285
  55.       Left            =   1200
  56.       TabIndex        =   2
  57.       Text            =   "6.2832"
  58.       Top             =   45
  59.       Width           =   615
  60.    End
  61.    Begin VB.PictureBox picCanvas 
  62.       AutoRedraw      =   -1  'True
  63.       Height          =   4815
  64.       Left            =   0
  65.       ScaleHeight     =   4755
  66.       ScaleWidth      =   4755
  67.       TabIndex        =   0
  68.       Top             =   840
  69.       Width           =   4815
  70.    End
  71.    Begin VB.Label Label1 
  72.       Caption         =   "Y Scale"
  73.       Height          =   255
  74.       Index           =   3
  75.       Left            =   1560
  76.       TabIndex        =   10
  77.       Top             =   495
  78.       Width           =   615
  79.    End
  80.    Begin VB.Label Label1 
  81.       Caption         =   "X Scale"
  82.       Height          =   255
  83.       Index           =   2
  84.       Left            =   0
  85.       TabIndex        =   8
  86.       Top             =   480
  87.       Width           =   615
  88.    End
  89.    Begin VB.Label Label1 
  90.       Caption         =   "dt"
  91.       Height          =   255
  92.       Index           =   1
  93.       Left            =   1920
  94.       TabIndex        =   5
  95.       Top             =   60
  96.       Width           =   255
  97.    End
  98.    Begin VB.Label Label1 
  99.       Caption         =   "<= t <="
  100.       Height          =   255
  101.       Index           =   0
  102.       Left            =   645
  103.       TabIndex        =   1
  104.       Top             =   60
  105.       Width           =   495
  106.    End
  107. Attribute VB_Name = "frmCircle2"
  108. Attribute VB_GlobalNameSpace = False
  109. Attribute VB_Creatable = False
  110. Attribute VB_PredeclaredId = True
  111. Attribute VB_Exposed = False
  112. Option Explicit
  113. Private Radius As Single
  114. ' Draw the curve on the indicated picture box,
  115. ' scaled.
  116. Private Sub DrawCurve(ByVal pic As PictureBox, ByVal start_t As Single, ByVal stop_t As Single, ByVal dt As Single, ByVal x_scale As Single, ByVal y_scale As Single)
  117. Dim cx As Single
  118. Dim cy As Single
  119. Dim t As Single
  120.     cx = pic.ScaleLeft + pic.ScaleWidth / 2
  121.     cy = pic.ScaleTop + pic.ScaleHeight / 2
  122.     pic.Cls
  123.     pic.CurrentX = cx + x_scale * X(start_t)
  124.     pic.CurrentY = cy + y_scale * Y(start_t)
  125.     t = start_t + dt
  126.     Do While t < stop_t
  127.         pic.Line -(cx + x_scale * X(t), cy + y_scale * Y(t))
  128.         t = t + dt
  129.     Loop
  130.     pic.Line -(cx + x_scale * X(stop_t), cy + y_scale * Y(stop_t))
  131. End Sub
  132. ' The parametric function Y(t).
  133. Private Function Y(ByVal t As Single) As Single
  134.     Y = Radius * Sin(t)
  135. End Function
  136. ' The parametric function X(t).
  137. Private Function X(ByVal t As Single) As Single
  138.     X = Radius * Cos(t)
  139. End Function
  140. Private Sub cmdGo_Click()
  141. Dim tmin As Single
  142. Dim tmax As Single
  143. Dim dt As Single
  144. Dim x_scale As Single
  145. Dim y_scale As Single
  146.     tmin = CSng(txtTmin.Text)
  147.     tmax = CSng(txtTmax.Text)
  148.     dt = CSng(txtDt.Text)
  149.     x_scale = CSng(txtXScale.Text)
  150.     y_scale = CSng(txtYScale.Text)
  151.     If picCanvas.ScaleWidth / x_scale < picCanvas.ScaleHeight / y_scale Then
  152.         Radius = picCanvas.ScaleWidth * 0.45 / x_scale
  153.     Else
  154.         Radius = picCanvas.ScaleHeight * 0.45 / y_scale
  155.     End If
  156.     DrawCurve picCanvas, tmin, tmax, dt, x_scale, y_scale
  157. End Sub
  158. Private Sub Form_Load()
  159. Const PI = 3.14159265
  160.     txtTmin.Text = Format$(0, "0.00")
  161.     txtTmax.Text = Format$(2 * PI, "0.00")
  162.     txtDt.Text = "0.1"
  163. End Sub
  164. Private Sub Form_Resize()
  165. Dim lft As Single
  166. Dim hgt As Single
  167.     lft = txtDt.Left + txtDt.Width
  168.     If lft < ScaleWidth - cmdGo.Width Then lft = ScaleWidth - cmdGo.Width
  169.     cmdGo.Left = lft
  170.     hgt = ScaleHeight - picCanvas.Top
  171.     If hgt < 120 Then hgt = 120
  172.     picCanvas.Move 0, picCanvas.Top, ScaleWidth, hgt
  173. End Sub
  174.